package com.xhs.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.xhs.entity.User;
import com.xhs.mapper.UserMapper;
import com.xhs.service.UserService;


@Service
@Transactional  //此处不再进行创建SqlSession和提交事务，都已交由spring去管理了。
public class UserServiceImpl implements UserService {
	
	@Autowired
	private UserMapper mapper;

	public boolean add(User user) {
		return mapper.add(user) > 0 ? true : false;
	}
	
	public boolean delete(int id) {
		return mapper.delete(id) > 0 ? true : false;
	}

	public boolean update(User user) {
		return mapper.update(user) > 0 ? true : false;
	}
	
	public User getById(int id) {
		return mapper.getById(id);
	}

	public List<User> getAll(User user) {
		return mapper.getAll(user);
	}
	
	public List<User> query(Page<User> pager, User user) {
		PageHelper.startPage(pager.getPageNum(),pager.getPageSize());
		List<User> list = mapper.query(user);
		return list;
	}

	public User getByUserName(String userName) {
		return mapper.getByUserName(userName);
	}

}
